package com.example.sample.activity;

import com.example.app.BaseActivity;
import com.example.sample.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;

import net.liteheaven.xblib.widget.edittext.FixedLineCountEditText;
import net.liteheaven.xblib.widget.layout.InterceptLinearLayout;

public class TouchEventActivity extends BaseActivity {

	private InterceptLinearLayout llParent;
	private InterceptLinearLayout ivChild;
	private FixedLineCountEditText logEdit;
    private final String PARENT = "parent";
    private final String CHILD = "child";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_touch_event);
		llParent = (InterceptLinearLayout) findViewById(R.id.llParent);
		ivChild = (InterceptLinearLayout)findViewById(R.id.ivChild);
		logEdit = (FixedLineCountEditText)findViewById(R.id.logEdit);
        logEdit.setMaxLineCount(20);
		
		llParent.setName(PARENT);
		llParent.setListener(getParentListener());
		ivChild.setName(CHILD);
		ivChild.setListener(getChildListener());
	}

    private InterceptLinearLayout.InterceptListener getParentListener(){
        return new InterceptLinearLayout.InterceptListener(){

            @Override
            public void addLog(String content) {
                logEdit.appendLine(content);
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                boolean ret = false;
                if (ev.getAction() == MotionEvent.ACTION_DOWN){
                    ret = false;
                }
                return ret;
            }

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                return false;
            }
        };
    }

    private InterceptLinearLayout.InterceptListener getChildListener(){
        return new InterceptLinearLayout.InterceptListener(){

            @Override
            public void addLog(String content) {
                logEdit.appendLine(content);
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                return false;
            }

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                return false;
            }
        };
    }
}
